<template>
	<view class="container">
		<view class="p10">
			<u--input prefixIcon="search" placeholder="请输入规格组名称" border="none" shape="circle"
				:customStyle="{background:'#f5f5f5',height:'60rpx',paddingLeft:'20rpx'}" v-model="params.name"
				@input="toSearch">
			</u--input>
		</view>
		<view class="" v-if="tableData.length != 0">
			<view class="card c3 mb10 cshow" v-for="(item,index) in tableData" :key="item.id">
				<view class="item_container">
					<view class="item">规格名称：{{item.rule_name}}</view>
					<view class="item">规格：{{item.attr_name}}</view>
					<view class="item">规格属性：
						<span v-for="(item, index) in item.attr_value" :key="index" v-text="item"
							style="display: block"></span>
					</view>
				</view>
				<u-divider></u-divider>
				<view class="footer">
					<view class="footer_item" @click="edit(item)">编辑</view>
					<view class="footer_item" @click="deleteProduct(item)">删除
					</view>
				</view>
			</view>
			<view class="" style="width: 100%;height: 140rpx;"></view>
		</view>
		<view v-if="tableData.length==0" class="np f-c-c">
			<view class="iconfont icon-queshengtu cb" style="font-size: 90rpx;"></view>
			<view class="f12 cb mt20">暂无数据</view>
		</view>
		<view class="navbar2 bt f-row">
			<view class="f-c" style="width: 168rpx;background: #FBFBFB;">规格组设置</view>
			<view class="f-1 f-row bf">
				<template v-for="(v, i) in navs">
					<view class="f-1 f-y-c" @click="djTab(v)" :key="i" v-if="menus.includes(v.role)">
						<view class="wh f-c f-y-c">
							<text class="cf7c mr10" :style="{ color: subColor ,fontSize:'38rpx'}"
								:class="['icon' + v.i, 'iconfont f20']"></text>
							<view class="">{{ v.t }}</view>
						</view>
					</view>
				</template>
			</view>
		</view>
		<u-popup :show="chainShow" @close="chainShow = false" mode="center" :round="10" :safeAreaInsetBottom="false">
			<view class="popup">
				<u--form :model="ruleForm" ref="ruleFormRef" labelWidth="70">
					<u-form-item label="规格模板名称：" prop="rule_name">
						<u--input placeholder="请输入标题名称" border="surround" v-model="ruleForm.rule_name"></u--input>
						<uni-icons type="plus" :color="subject_color" size="28"></uni-icons>
					</u-form-item>
					<!-- <u-form-item>
						<view class="" v-for="(item, index) in formDynamic.spec" :key="index">
							<span class="mr5">{{ item.value }}</span>
							
							<span v-for="(j, indexn) in item.detail" :key="indexn"></span>
							
							<u--input placeholder="请输入属性名称" border="surround" v-model="item.detail.attrsVal"></u--input>
						</view>
					</u-form-item> -->
				</u--form>
				<u-button text="确定" type='primary' @click="submit"></u-button>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import siteroot from '@/custom/siteroot.js';
	import {
		mapState,
	} from 'vuex'
	export default {
		data() {
			return {
				params: {
					page: 1,
					limit: 10,
					is_deleted: 0,
					name: ''
				},
				tableData: [],
				navs: [{
					i: '-jiahao',
					k: 'xjsp',
					url: 'xzlx',
					t: '规格组添加',
					role: 'chain_stores/chainStores/add'
				}],
				ruleForm: {
					rule_name: ''
				},
				chainShow: false,
				subject_color: uni.getStorageSync("subject_color"),
				hasLoadedData: false
			}
		},
		methods: {
			toSearch() {
				this.hasLoadedData = false;
				this.getlists()
			},
			// 列表
			getlists() {
				uni.showLoading()
				this.beg.request({
						url: '/admin/product.GoodsRule/getList',
						method:'post',
						data: this.params
					}).then((res) => {
						if (res.code == 1) {
							let newData = res.data.list
							if (!this.hasLoadedData) {
								this.tableData = newData;
								this.hasLoadedData = true;
							} else {
								this.tableData = this.tableData.concat(newData);
							}
						}
						uni.hideLoading()
					})
					.catch(() => {
						uni.hideLoading()
					})
			},
			// 删除
			deleteProduct(val) {
				uni.showModal({
					title: '提示',
					content: '确定删除该商品？',
					success: (res) => {
						if (res.confirm) {
							this.beg.request({
								url: '/admin/product.GoodsRule/deleted',
								method: 'POST',
								data: {
									id: val.id,
									is_deleted: 1
								}
							}).then(res => {
								if (res.code == 1) {
									uni.$u.toast(res.msg)
									setTimeout(res => {
										this.hasLoadedData = false;
										this.params.page = 1;
										this.getlists()
									}, 800)
								} else {
									uni.$u.toast(res.msg)
								}
							})
						}
					}
				})
			},
			// 编辑
			edit(val) {
				this.chainShow = true
			}
		},
		computed: {
			...mapState({
				menus: state => state.menus,
			}),
		},
		onLoad() {
			this.getlists()
		},
		onReachBottom() {
			this.params.page++
			this.getlists()
		}
	}
</script>

<style>
	page {
		background-color: #fff;
	}
</style>
<style lang="scss" scoped>
	.card {
		width: 94%;
		margin: 0 auto;
		margin-top: 38rpx;
	}

	.item_container {
		.item {
			font-size: 29rpx;
			font-weight: 500;
			color: #000;
			margin-top: 15rpx;
		}

		.stutas {
			display: flex;
			align-items: center;
			margin-top: 15rpx;
		}
	}

	.footer {
		display: flex;
		justify-content: flex-start;
		align-items: center;

		.footer_item {
			width: 125rpx;
			height: 55rpx;
			border-radius: 8rpx;
			background-color: #fdda34;
			color: #000;
			font-weight: 600;
			display: flex;
			justify-content: center;
			align-items: center;
		}

		.footer_item:not(:first-child) {
			margin-left: 30rpx;
		}
	}

	.navbar2 {
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		height: 100rpx;
		background: #fff;
		box-shadow: 0 0rpx 8rpx 4rpx rgba(0, 0, 0, 0.05);
	}

	.popup {
		width: 90vw;
		padding: 40rpx 20rpx;
	}
</style>